package com.leetcode.algorithm.y22.m07;

import com.leetcode.algorithm.common.TreeNode;

/**
 * 404. 左叶子之和
 * 
 * https://leetcode.cn/problems/sum-of-left-leaves/
 * 
 * @author jie.deng
 *
 */
class Question0404Solution02 {
	
	public int sumOfLeftLeaves(TreeNode root) {
		if (root == null) {
			return 0;
		}
		int midValue = 0;
		if (root.left != null && root.left.left == null && root.left.right == null) {
			midValue = root.left.val;
		}
		int leftValue = sumOfLeftLeaves(root.left);
		int rightValue = sumOfLeftLeaves(root.right);
		return midValue + leftValue + rightValue;
	}
    
}